# ---------------------------------------------------------------------------- #
# Make a common config both for physical machine and virtual machine 
# ---------------------------------------------------------------------------- #
# Reserve portion of memory to system service, 2000MB for physical machine,
# 500MB for other machine, including virtual machine
<% if @ifvirmacine %>
RESERVED_MEMORY = 1500
START = $(START) && (TARGET.AcctGroupUser!="offline")
<% else %>
RESERVED_MEMORY = 2000
<% end %>
# ---------------------------------------------------------------------------- #
# Calculate the amount of slots, according ot the minimam memory size owned by 
# each slot. Each slot owns 2500MB memory at least.
# ---------------------------------------------------------------------------- #
# How large size of memory each slot should have at least
IHEP_MIN_MEM_PER_SLOT = 2500

# The remaining memory which subtracts the reserved memory from total memory
IHEP_REMAINING_MEMORY = ( $(DETECTED_MEMORY) - $(RESERVED_MEMORY) )

# The average physical memory owned by each cpu on this machine
IHEP_AVG_MEM_PER_CPU = ( $(IHEP_REMAINING_MEMORY) / $(DETECTED_CPUS) )

# Calculate the minimum memory threshold
IHEP_MIN_MEM_THRESHOLD = 2500

IHEP_MIN_MEM_THRESHOLD_RATE = ( $(IHEP_MIN_MEM_THRESHOLD) / $(IHEP_AVG_MEM_PER_CPU) )

IHEP_MIN_MEM_THRESHOLD_RATE_INT = $INT(IHEP_MIN_MEM_THRESHOLD_RATE)

# If the memory size per cpu is less than minimum memory threshold, reduce
# the amount of slots by memory claimed, guarantee each slot claims memory
# size which is not less than the value got from IHEP_MIN_MEM_PER_SLOT
if $(IHEP_MIN_MEM_THRESHOLD_RATE_INT)
  IHEP_NUM_SLOTS = ( $(IHEP_REMAINING_MEMORY) / $(IHEP_MIN_MEM_PER_SLOT) )
  NUM_SLOTS = $INT(IHEP_NUM_SLOTS)
endif

